<template>
	<view class="wrap">
		<view class="top">
			<view class="item">
				<view class="left">收货人</view>
				<input v-model="form.pname" type="text" placeholder-class="line" placeholder="请填写收货人姓名" />
			</view>
			<view class="item">
				<view class="left">手机号码</view>
				<input v-model="form.phone" type="text" placeholder-class="line" placeholder="请填写收货人手机号" />
			</view>

			<view class="item address">
				<view class="left">地址</view>
				<textarea v-model="form.addressname" type="text" placeholder-class="line" placeholder="街道、楼牌等" />
			</view>
		</view>
		<view class="bottom">
			<view class="item">
				<view class="left">标签</view>
				<input v-model="form.tag" type="text" placeholder-class="line" placeholder="家" />
			</view>
			<view class="default">
				<view class="left">
					<view class="set">设置默认地址</view>
					<view class="tips">提醒：每次下单会默认推荐该地址</view>
				</view>
				<view class="right"><switch color="red" @change="setDefault" /></view>
			</view>
		</view>
		
		<u-button @click="Create" class="btn" type="primary" shape="circle" text="修改"></u-button>
		<u-notify ref="tos" message=""></u-notify>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form:{},
			city:'',
			address:''
		};
	},
	methods: {
		getObject(id){
			uni.$u.http.get('/address/'+id).then(res=>{
				console.log(res.data);
				this.form = res.data.data
			})
		},
		Create(){
			
			if(this.form.pname.length < 1 ){
				this.$refs.tos.error('收货人不能为空！')
				return
			}
			if(this.form.phone.length < 1 ){
				this.$refs.tos.error('电话不能为空！')
				return
			}
			if(this.form.addressname.length < 1 ){
				this.$refs.tos.error('地址不能为空！')
				return
			}
			if(this.form.tag.length < 1 ){
				this.form.tag = '家'
			}
			
			console.log(this.form);
			uni.$u.http.put('/address',this.form).then(res=>{
				if(res.data.code === 200){
					this.$refs.tos.success('修改成功')
					uni.redirectTo({
						url:'/pages/address/address'
					})
				}else{
					this.$refs.tos.error(res.data.msg)
				}
			})
		},
		
		showRegionPicker() {
			this.show = true;
		}
	},
	onLoad(options){
		console.log(options)
		this.getObject(options.aid)
	}
	
};
</script>

<style lang="scss" scoped>
.btn{
	
}
/deep/ .line {
	color: $u-light-color;
	font-size: 28rpx;
}
.wrap {
	background-color: #f2f2f2;
	.top {
		background-color: #ffffff;
		border-top: solid 2rpx $u-border-color;
		padding: 22rpx;
		.item {
			display: flex;
			font-size: 32rpx;
			line-height: 100rpx;
			align-items: center;
			border-bottom: solid 2rpx $u-border-color;
			.left {
				width: 180rpx;
			}
			input {
				text-align: left;
			}
		}
		
		.address {
			padding: 20rpx 0;
			textarea {
				// width: 100%;
				height: 150rpx;
				background-color: #f7f7f7;
				line-height: 60rpx;
				margin: 40rpx auto;
				padding: 20rpx;
			}
		}
		.site-clipboard {
			padding-right: 40rpx;
			textarea {
				// width: 100%;
				height: 150rpx;
				background-color: #f7f7f7;
				line-height: 60rpx;
				margin: 40rpx auto;
				padding: 20rpx;
			}
			.clipboard {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 26rpx;
				color: $u-tips-color;
				height: 80rpx;
				.icon {
					margin-top: 6rpx;
					margin-left: 10rpx;
				}
			}
		}
	}
	.bottom {
		margin-top: 20rpx;
		padding: 40rpx;
		padding-right: 0;
		background-color: #ffffff;
		font-size: 28rpx;
		.tag {
			display: flex;
			.left {
				width: 160rpx;
			}
			.right {
				display: flex;
				flex-wrap: wrap;
				.tags {
					width: 140rpx;
					padding: 16rpx 8rpx;
					border: solid 2rpx $u-border-color;
					text-align: center;
					border-radius: 50rpx;
					margin: 0 10rpx 20rpx;
					display: flex;
					font-size: 28rpx;
					align-items: center;
					justify-content: center;
					color: $u-content-color;
					line-height: 1;
				}
				.plus {
					//padding: 10rpx 0;
				}
			}
		}
		.default {
			margin-top: 50rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: solid 2rpx $u-border-color;
			line-height: 64rpx;
			.tips {
				font-size: 24rpx;
			}
			.right {
			}
		}
	}
}
</style>
